import 'dart:io';

import 'package:appflutterhomeschool/provider/provider_widget.dart';
import 'package:appflutterhomeschool/res/colors.dart';
import 'package:appflutterhomeschool/res/styles.dart';
import 'package:appflutterhomeschool/ui/widgets/button_widget.dart';
import 'package:appflutterhomeschool/ui/widgets/widgets.dart';
import 'package:appflutterhomeschool/utils/utils.dart';
import 'package:appflutterhomeschool/view_model/login/login_view_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

///用户：Nine Tailed Fox
///时间：2020/6/9
///邮箱：1037438704@qq.com
///功能：登录页面
class LoginPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => FocusScope.of(context).requestFocus(FocusNode()),
      child: ProviderWidget<LoginViewModel>(
        model: LoginViewModel(context),
        onModelReady: (value) => value.initView(),
        builder: (context, viewModel, child) {
          return Scaffold(
            resizeToAvoidBottomInset: false,
            backgroundColor: Colors.white,
            appBar: AppBar(
              brightness: Brightness.light,
              elevation: 0,
              leading: IconButton(
                icon: Icon(
                  Icons.clear,
                  color: Colors.black,
                ),
                onPressed: () => exit(0),
              ),
            ),
            body: Container(
              padding: EdgeInsets.only(
                  left: ScreenUtil().setWidth(125),
                  right: ScreenUtil().setWidth(125)),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Container(
                      alignment: Alignment.center,
                      child: Text("密码登录", style: TextStyles.textDark70)),
                  SizedBox(height: ScreenUtil().setWidth(100)),
                  TextFieldWidget(
                      textEditingController: viewModel.phoneText,
                      hintText: "请输入手机号码"),
                  TextFieldWidget(
                    textEditingController: viewModel.passwordText,
                    hintText: "请输入密码",
                    obscureText: viewModel.obscureText,
                    iconEye: GestureDetector(
                      child: Icon(
                        viewModel.obscureText
                            ? Icons.visibility_off
                            : Icons.remove_red_eye,
                        color: Colours.text_dark,
                        size: ScreenUtil().setSp(62),
                      ),
                      onTap: () => viewModel.initEvent(0),
                    ),
                  ),
                  SizedBox(height: ScreenUtil().setSp(80)),
                  SureMaterialButton(
                    buttonName: "登录",
                    onPressed: () => viewModel.initEvent(4),
                  ),
                  SizedBox(height: ScreenUtil().setSp(43)),
                  Row(
                    children: <Widget>[
                      Expanded(
                          child: Container(
                        child: GestureDetector(
                          child: Text("忘记密码"),
                          onTap: () => viewModel.initEvent(2),
                        ),
                        alignment: Alignment.centerLeft,
                      )),
                      GestureDetector(
                        child: Text("没有账号?"),
                        onTap: () => viewModel.initEvent(1),
                      ),
                    ],
                  ),
                  Container(
                    margin: EdgeInsets.only(top: ScreenUtil().setSp(155)),
                    child: Image.asset(Utils.getImgPath("login_kuaijiedenglu")),
                  ),
                  Container(
                    margin: EdgeInsets.only(top: ScreenUtil().setSp(86)),
                    child: GestureDetector(
                      child: Image.asset(Utils.getImgPath("login_weixin")),
                      onTap: () => viewModel.initEvent(3),
                    ),
                  ),
                ],
              ),
            ),
          );
        },
      ),
    );
  }
}
